# for i in range(10, 30):
#     z = i ** 4
#     x = i ** 3
#     a = z // 100000
#     b = z // 10000 % 10
#     c = z // 1000 % 10
#     d = z // 100 % 10
#     e = z // 10 % 10
#     f = z % 10
#     g = x // 1000
#     h = x // 100 % 10
#     j = x // 10 % 10
#     k = x % 10
#     s = (a, b, c, d, e, f, g, h, j, k)
#     if len(set(s)) == 10:
#         print(i)
#
# for i in range(10, 30):
#     i3 = str(i ** 3)
#     i4 = str(i ** 4)
#     if len(i3) == 4 and len(i4) == 6:
#         if len(set(i3 + i4)) == 10:
#             print(i)
#             print(i3 + i4)


# list1 = ['a.py', 'b.jpg', 'c.gif', 'd.map', 'e.png', 'f.jpg', 'k.txt', 'f.gif', 'h.png', 'm.doc']
# for i in list1:
#     if '.jpg,.gif,.png' in i:
#         print(i)


# 公共操作
# str1 = 'aa'  # 合并  字符串，列表，元组
# str2 = 'bb'
# str3 = str1 + str2
# print(str3)

# print('*' * 10)  # 复制  字符串，列表，元组
# list1 = ['hello']
# print(list1 * 4)
# tuple1 = (1, 2)
# print(tuple1 * 4)

# 判断  in , not in
# len(), max(), min(), range(start,end,step)生成的序列不包含end数字, del()
# enumerate(可遍历对象，start=0),start 用来设置遍历起始下标默认为0.

# list1 = ['a', 'b', 'c', 'd', 'e']
# # for i in enumerate(list1):
# #     print(i)
# set1 = ('a', 'b', 'c')
# print(tuple(list1))  # 容器类型转换
# print(list(set1))
# print(set(list1))  # 列表去重


# 列表推导式
# list1 = []
# i = 0
# while i < 10:    # while循环
#     list1.append(i)
#     i += 1
# print(list1)
# for i in range(10):    # for循环
#     list1.append(i)
# print(list1)
# list1 = [i for i in range(10)]   # 列表推导式
# print(list1)
# list1=[i for i in range(0,10,2)]
# list1 = [i for i in range(0, 10) if i % 2 == 0]
# print(list1)
# list1 = [(i, j) for i in range(2, 4) for j in range(0, 3)]
# print(list1)

# list1 = ['name', 'age', 'gender']  # 将两个列表合并为一个字典
# list2 = ['Alex', '17', '男']
# dict3 = {list1[i]: list2[i] for i in range(len(list1))}
# print(dict3)

# dict1 = {i: i ** 2 for i in range(1, 5)}
# print(dict1)
#  # 提取字典中的数值
# counts = {'MBP': 268, 'HP': 125, 'DELL': 201, 'LENOVO': 199, 'ACER': 99}
# count1 = {key: value for key, value in counts.items() if value >= 200}
# print(count1)

# 集合推导式
# list1 = [1, 2, 3, 1]
# set1 = {i ** 2 for i in list1}
# print(set1)

# set1 = {i for i in range(0, 10, 2)}
# print(set1)

# c = {1, 2, 3}
# c.add(4)
# print(c)
# c.update({4, 5})
# print(c)


# 函数
# def add(a, b):
#     result = a + b
#     print(result)
#
#
# add(2, 3)


# def add(a, b):
#     return a + b
#
#
# result = add(2, 3)
# print(result)


# 函数的说明文档
# def add(a, b):
#     """求和函数"""
#     return a + b
#
#
# help(add)
#
# def print_line():
#     print('-'*20)
# Putthipong Assaratanakul
# Krit Amnuaydechkorn

# 变量作用域
# a=100
# def testA():
#     print(a)
#
# def testB():
#     global a
#     a = 200
#     print(a)
#
#
# testA()
# testB()
# print(testA)
# print(testB)

# 不定长参数def 函数名(*参数)不确定调用参数个数


# 拆包：元组
# def return_num():
#     return 100, 200
#
#
# num1, num2 = return_num()
# print(num1)
# print(num2)

# 拆包：字典
# dict1 = {'name': 'Tom', 'age': 18}
# a, b = dict1
# print(a)  # 返回key值
# print(b)
#
# print(dict1[a])  # 返回value值
# print(dict1[b])

# a = 10  # 交换数值，找中间变量传值
# b = 20
# c = 0
# c = a
# a = b
# b = c
# print(a, b)

# a, b = 1, 2  # 直接交换
# a, b = b, a
# print(a)
# print(b)

# 找出列表中单词长度最长的
def test1():
    global item
    a = ['hello', 'world', 'yoyo', 'congratulations']
    length = len(a[0])
    for i in a:
        if len(i) > length:
            item = i
    return item


test1()
print(item)


def test2():      # 将列表数据按绝对值大小排序
    s = set()
    i = 0
    a = [1, -6, 2, -5, 9, 4, 20, -3]
    for a[i] in a:         # for i in a: list1.append(abs(i))
        z = abs(a[i])
        s.add(z)
    print(s)
    return s


test2()  # print(test2())


def test3():                       # 交换字典的key,value值
    dict1 = {'a': 1, 'b': 2, 'c': 3}
    dict2 = {key: value for value, key in dict1.items()}
    return dict2


print(test3())

